home *** CD-ROM | disk | FTP | other *** search
/ CICA 1993 April / CICA MS Windows - April 1993.iso / unzipped / programr / listings / blx12 / winsb.h < prev    next >
Text File  |  1991-05-02  |  4KB  |  126 lines

  1. // winsb.h
  2.  
  3. #if !defined(WINSB_H)
  4.  
  5. #include<stdlib.h>
  6.  
  7. #include"stddefs.h"
  8.  
  9. const MAXPOSITION = 32767;
  10.  
  11. /* WinScrollBar
  12.  
  13. This class creates a scrollbar, either horizontal
  14. or vertical, and contains code to manage them.
  15. */
  16. class WinScrollBar
  17.     {
  18.         void SetDefaults(void)
  19.             {
  20.             numLineScroll = numPageScroll = 1;
  21.             minPosition = 0;
  22.             maxPosition = MAXPOSITION;
  23.             oldPosition = curPosition = 0;
  24.             redraw = TRUE;
  25.             myWin = NULL;
  26.             barType = SB_VERT;
  27.             created = FALSE;
  28.             }
  29.  
  30.     protected:
  31.         int numLineScroll;      // number of positions to scroll by line
  32.         int numPageScroll;      // number of positions to scroll by page
  33.  
  34.         int curPosition;        // current thumb position
  35.         int oldPosition;        // old thumb position
  36.         int minPosition;        // lowest position on the scale
  37.         int maxPosition;        // highest position on the scale
  38.  
  39.         HWND    myWin;          // window to which SB is attached
  40.         int     barType;        // SB_CTL, SB_HORZ, SB_VERT
  41.         BOOL    redraw;         // TRUE if we should redraw when range changes
  42.         BOOL    created;
  43.  
  44.     public:
  45.         WinScrollBar(HWND hWnd, int bar)
  46.             {
  47.             SetDefaults();
  48.             SetType(bar);
  49.             SetHandle(hWnd);
  50.             }
  51.         WinScrollBar(void)
  52.             {
  53.             SetDefaults();
  54.             }
  55.  
  56.         void Init(HWND hWnd, int bar, int minpos, int maxpos)
  57.             {
  58.             SetHandle(hWnd);
  59.             SetType(bar);
  60.             SetRange(minpos,maxpos);
  61.             Show();
  62.             }
  63.  
  64.         void SetType(int bar)           {   barType = bar;      }
  65.         void SetHandle(HWND hWnd)       {   myWin = hWnd;       }
  66.         void SetRedraw(void)            {   redraw = TRUE;      }
  67.         void SetLineScroll(int lines)   {   numLineScroll = lines;  }
  68.         void SetPageScroll(int pages)   {   numPageScroll = pages;  }
  69.         void ClearRedraw(void)          {   redraw = FALSE;     }
  70.  
  71.         void SetCurPos(int curpos)
  72.             {
  73.             curPosition = curpos;
  74.             Update();
  75.             }
  76.         void SetMin(int minpos)
  77.             {
  78.             SetRange(minPosition = minpos,maxPosition);
  79.             }
  80.         void SetMax(int maxpos)
  81.             {
  82.             SetRange(minPosition,maxPosition = maxpos);
  83.             }
  84.  
  85.         int GetCurPos(void)             { return curPosition;   }
  86.         int GetMinPos(void)             { return minPosition;   }
  87.         int GetMaxPos(void)             { return maxPosition;   }
  88.  
  89.         void Update(void)
  90.             {
  91.             if(!created)
  92.                 SetRange(minPosition, maxPosition);
  93.             if(myWin)
  94.                 oldPosition = SetScrollPos(myWin,barType,curPosition,redraw);
  95.             }
  96.  
  97.         void SetRange(int minimum, int maximum)
  98.             {
  99.             if(myWin)
  100.                 {
  101.                 minPosition = minimum;
  102.                 maxPosition = maximum;
  103.                 SetScrollRange(myWin,barType,minPosition,maxPosition, redraw);
  104.                 }
  105.             created = TRUE;
  106.             }
  107.         void ScrollProc(WORD wParam, LONG lParam);
  108.         void ScrollUpdate(WORD wParam, LONG lParam)
  109.             {
  110.             ScrollProc(wParam, lParam);
  111.             Update();
  112.             }
  113.         void Hide(void)
  114.             {
  115.             ShowScrollBar(myWin,barType,FALSE);
  116.             }
  117.         void Show(void)
  118.             {
  119.             ShowScrollBar(myWin,barType,TRUE);
  120.             }
  121.     };
  122.  
  123.  
  124. #define WINSB_H
  125. #endif
  126.